<template>
  <div>
    <div>{{ teacher.name }}</div>
    <div>{{ teacher.age }}</div>
    <div>{{ teacher.salary }}</div>
    <button @click="timeFly">过了一年</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      money: 100,
      teacher: {
        name: 'harry',
        age: 28,
        salary: 3000,
      },
    }
  },
  methods: {
    salary(num) {
      this.money += num
    },
    timeFly() {
      this.teacher.age += 1
      this.teacher.salary += 500
    },
  },
  watch: {
    'teacher.age'(newValue) {
      if (newValue === 40) {
        alert('你可以退休了')
      }
    },
  },
}
</script>

<style scoped></style>
